<template>
    <Modal
        v-model="showModal.show"
        title="批量导出"
        class-name="vertical-center-modal">
        <div class="batch_download">
            <Alert type="warning"  show-icon style="font-size:12px;">如果有多个BOM编码，请换行输入</Alert>
            <p>
                <Input v-model="sCode" type="textarea" :rows="8" placeholder="请输入BOM编码" />
            </p>
        </div>
        <div slot="footer">
            <Button type="text" @click="cancel">取消</Button>
            <Button type="primary" :loading="loading" @click="downloadFn">确定</Button>
        </div>
    </Modal>
</template>
<script>
import { mapGetters } from 'vuex';
export default {
    props:{
        showModal:{
            type:Object
            ,default(){
                return {
                    show:false
                }
            }
        }
    }
    ,data(){
        return{
            sCode:''
            ,loading:false
        }
    }
    ,computed:{
      ...mapGetters({
        sUser:'sUser'
      })
    }
    ,methods: {
        downloadFn () {
            let t = this;
            let aCode = [];
            let sNewCode = t.sCode.replace(/\n|(\s+)/g,'#');
            if(!sNewCode){
                t.$Message.error({background: true,content: '请输入BOM编码'});
                return;
            }
            let sUrl = 'material/exportBom.htm?materialCode='+ encodeURIComponent(sNewCode);
            if(t.sUser == 'admin'){
                sUrl += ('&u=' + t.sUser);
            }
            location.href = gMain.apiPath + t.$router.options.base + sUrl;
            t.loading = false;
            t.showModal.show = false;
        },
        cancel () {
            let t = this;
            t.showModal.show = false;
        }
    }
}
</script>
<style lang="less">
    .batch_download{
        padding: 0 40px;
    }
</style>